﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BiliBiliCSharpStudy.old {
    class ClassDemo1Hello {
        public static void Demo() {
            //Test1();
            //Test2();
            //Test3();
            Test4();
        }

        public static void Test4() {
            Student13 stu1 = new Student13(1, "小明");
            Student13 stu2 = new Student13(2, "小强");
            Console.WriteLine(Student13.Amount);
        }

        // 反射
        public static void Test3() {
            Type type = typeof(Student13);
            dynamic stu = Activator.CreateInstance(type, 2, "小明");
            Console.WriteLine(stu.Name);
        }

        // 反射
        public static void Test2() {
            Type type = typeof(Student13);
            object o = Activator.CreateInstance(type, 2, "小明");
            Console.WriteLine(o.GetType().Name);
            Console.WriteLine(o is Student13);
            Student13 stu = o as Student13;
            Console.WriteLine(stu.Name);
        }

        public static void Test1() {
            Student13 stu = new Student13() { ID = 1, Name = "Tom" };
            Console.WriteLine(stu.ID);
            Console.WriteLine(stu.Name);
            stu.Report();
        }
    }

    class Student13 {

        public static int Amount { get; set; }
        //静态构造器
        static Student13() {
            Amount = 100;
        }

        public Student13() {
            Amount++;
        }

        public Student13(int id, string name) {
            this.ID = id;
            this.Name = name;
            Amount++;
        }

        // 析构器
        ~Student13() {
            Console.WriteLine("Bye bye! Release the system resources ...");
            Amount--;
        }

        public int ID { get; set; }
        public string Name { get; set; }
        public void Report() {
            Console.WriteLine($"I'm #{ID} student, my name is {Name}");
        }
    }
}
